package com.hc.likelistenmusic.adapter

import android.content.Context
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import com.hc.likelistenmusic.R
import com.hc.likelistenmusic.bean.OnlineMusicResponse

class OnlineMusicAdapter(var context: Context, var layoutId: Int, var list: List<OnlineMusicResponse>) : BaseAdapter<OnlineMusicResponse>(context,layoutId,list) {

    override fun bindViews(holder: BaseHolder, om: OnlineMusicResponse, position: Int) {
        var cl_fomri_root = holder.getView<ConstraintLayout>(R.id.cl_fomri_root)
        var tv_fomri_position = holder.getView<TextView>(R.id.tv_fomri_position)
        var tv_fomri_name = holder.getView<TextView>(R.id.tv_fomri_name)
        var tv_fomri_singer = holder.getView<TextView>(R.id.tv_fomri_singer)
        (position + 1).toString().let {
            tv_fomri_position.text = it
            tv_fomri_position.tag = position
            cl_fomri_root.tag = list[position]
        }
        list[position].let {
            tv_fomri_name.text = it.name
            tv_fomri_singer.text = it.singer
        }
    }

    override fun bindListener(holder: BaseHolder) {
        var cl_fomri_root = holder.getView<ConstraintLayout>(R.id.cl_fomri_root)
        var tv_fomri_position = holder.getView<TextView>(R.id.tv_fomri_position)
        cl_fomri_root.setOnClickListener {
            onItemClickListen?.onItemClick(cl_fomri_root.tag as OnlineMusicResponse,tv_fomri_position.tag as Int)
        }
    }
}